<?php
include("utils.php");
if($_SESSION['siteuserId']=="")
{
	header("location:start.php");
}
if($_POST['mode']=="change_status")
{
	change_status();
}
else
{
	main_content("main();");
}

function change_status()
{
   $sql = "UPDATE advertise_master SET advertiseStatus = if(advertiseStatus = 'N','Y','N') WHERE advertiseId = '".$_POST['Id']."' ";
	mysql_query($sql);
	$GLOBALS['err_msg']="Status Changed Successfully";
	main_content("main();");

}

function main()
{

if($_SESSION['languageId']!="")
{
	$languageId=$_SESSION['languageId'];
}
else
{
	$languageId='1';
}

if($_POST['site_type']!="")
{
 $sql_details="select AM.advertiseId,AM.adsiteId,SM.adSiteUrl,ADM.adSpaceName , DM.destinationUrl,DM.adTitle,DM.startDate,DM.endDate,DM.adPrice,SM.adSiteType,DM.advertiseStatus,DM.advertiseId as id from advertise_details AM ,adsite_master SM,adspace_master ADM,advertise_master DM where AM.adsiteId=SM.adsiteId and AM.adsiteId=ADM.adsiteId and AM.advertiseId=DM.advertiseId and SM.adSiteType='".$_POST['site_type']."' group by adDetailasId ";
}
elseif($_POST['site_status']!="")
{
 $sql_details="select AM.advertiseId,AM.adsiteId,SM.adSiteUrl,ADM.adSpaceName , DM.destinationUrl,DM.adTitle,DM.startDate,DM.endDate,DM.adPrice,SM.adSiteType,DM.advertiseStatus,DM.advertiseId as id from advertise_details AM ,adsite_master SM,adspace_master ADM,advertise_master DM where AM.adsiteId=SM.adsiteId and AM.adsiteId=ADM.adsiteId and AM.advertiseId=DM.advertiseId and DM.advertiseStatus='".$_POST['site_status']."' group by adDetailasId ";
}

else
{
   $sql_details="select AM.advertiseId,AM.adsiteId,SM.adSiteUrl,ADM.adSpaceName , DM.destinationUrl,DM.adTitle,DM.startDate,DM.endDate,DM.adPrice,SM.adSiteType,DM.advertiseStatus,DM.advertiseId as id from advertise_details AM ,adsite_master SM,adspace_master ADM,advertise_master DM where AM.adsiteId=SM.adsiteId and AM.adsiteId=ADM.adsiteId and AM.advertiseId=DM.advertiseId group by adDetailasId ";

}
$query_details=mysql_query($sql_details);
$num=mysql_num_rows($query_details);

 $query_site_name=mysql_query("select adSiteName from adsite_master where siteuserId='".$_SESSION['siteuserId']."' and langId='".$languageId."'");

?><script language="JavaScript">
function show(argu)
{
	//alert(argu);
	document.adspaces.site_type.value=argu;
	document.adspaces.submit();
}
function show_status(argu)
{
	//alert(argu);
	document.adspaces.site_status.value=argu;
	document.adspaces.submit();
}
function show_site_nane(argu1)
{
	//alert(argu1);
	document.adspaces.site_name.value=argu1;
	document.adspaces.submit();
}
function change_status(argu3)
{
	//alert(argu3);

	document.adspaces.Id.value=argu3;
	document.adspaces.mode.value="change_status";
	document.adspaces.submit();
}
</script>

<form name="adspaces" action="" method="POST">
<input type="hidden" name="site_type" value="">
<input type="hidden" name="site_status" value="">
<input type="hidden" name="mode" value="">
<input type="hidden" name="site_name" value="">
<input type="hidden" name="Id" value="">

<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center">
              <tr>
                <td valign="top" align="center"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td valign="top"></td>
                    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td class="PinkTwosideBorder" valign="top"><table width="100%" class="center" cellspacing="0" cellpadding="0">
 
  <tr>
    <td align="left" valign="top">

<!-- start table  -->

<table id="spacesList" style="width:100%; margin-left:1px; position:relative" align="center" border="0" >

<tr>
    <td colspan="2" align="center" class="sky font-18" style="padding-bottom:20px;">
	My Websites
	</td>
<?php
if($GLOBALS['err_msg']!="")
{
?>
<tr>
    <td colspan="2" align="center" class="font-11 latest_heading2" style="padding-bottom:10px;">
	<strong><?php echo $GLOBALS['err_msg'];?></strong>
	</td>
</tr>
<?php
}
?>
  <tr>
    <td style="text-align:left;white-space:nowrap;padding-bottom:10px;" colspan="2">

    
      <span class="font-12 black advertise_tableTxt">
        Site Type:
        <select id="adspaceType" name="adspace_type" class="InputBox" style="width: 100px;" maxlength="150">
          <option value="">--Select--</option>
          <option value="text" onclick="return show('MOBILE');">MOBILE</option>
          <option value="banner" onclick="return show('WEB');">WEB</option>
          </select>

      </span>

		<span class="font-12 black advertise_tableTxt">
        Status:
        <select id="adspaceType" name="adspace_type" class="InputBox" style="width: 150px;" maxlength="150">
          <option value="">--Select--</option>
          <option value="text" onclick="return show_status('Y');">Active</option>
          <option value="banner" onclick="return show_status('N');">Block</option>
		 <option value="banner" onclick="return show_status('P');">Pending</option>
         </select>

      </span>

		<span class="font-12 black advertise_tableTxt">
	<input type="button" name="add_button" id="add" value="Show All" class="blank-button-big-add" onclick="javascript: window.location='accept_order.php';" />
	</span>
	
    </td>
   
  </tr>


  <tr>

    <td colspan="2">

<table border="1" cellspacing="0" cellpadding="0" width="100%">
 <TR>
  <TD align="center">
   <table width="100%" class="login_txt" cellspacing="1" cellpadding="0" border="0">
    <tr style="background-color:gray">
        <th class="listHeader" align="center" nowrap="true">
        <strong>Website</strong>
        </th>
        <th class="listHeader" align="center" nowrap="true">
        Ad Space
        </th>
		 <th class="listHeader" align="center" nowrap="true">
        Site type
        </th>
        <th class="listHeader" align="center" nowrap="true">
         Customer URL
        </th>
        
        <th class="listHeader" align="center" nowrap="true">
        Headline
        </th>
		<th class="listHeader" align="center" nowrap="true">
         Dates Run
       </th>

		<th class="listHeader" align="center" nowrap="true">
         Price
       </th>

		<th class="listHeader" align="center" nowrap="true">
         Status
       </th>

      <!-- <th colspan="1" class="listHeader" align="center" nowrap="true">Status</th>
       </tr>-->

	    <?php
		if($num>0)
		{

		$loop=0;
		while($rec_details=mysql_fetch_array($query_details))
		{
		$loop++;
		if($loop%2 == 0) 
		{
		$class1="normalActive2";
		$class2="normal2";
		$class3="normal2";
		$class4="gray_sitename2";
		}
		else 
		{
		$class1="normalActive";
		$class2="normal";
		$class3="normal";
		$class4="white_sitename2";
		}

	    ?>

        <tr onmouseover="this.className='<?php echo $class1;?>'" onmouseout="this.className='<?php echo $class2;?>'" class="<?php echo $class3;?>">

        <td class="<?php echo $class4;?>" align="left">

		<a href="edit_websites.php?sid=<?php echo $rec_details['adSiteUrl'];?>" class="register_link"><?php echo $rec_details['adSiteUrl'];?></a>

		</td>
        <td class="<?php echo $class4;?>" align="left">
<?php
 $date1=date('m/d/Y',strtotime($rec_days['startDate']));
 $date2=date('m/d/Y',strtotime($rec_days['endDate']));

   $date=dateDiff("/", $date2, $date1);

echo $rec_details['adSpaceName']
?>
                         
                        </td>

		<td class="<?php echo $class4;?>" align="left">
		<?php
		echo $rec_details['adSiteType'];
		?>
		&nbsp;
		</td>

        <td class="<?php echo $class4;?>" align="left">
		<?php
		echo $rec_details['destinationUrl'];
		?>
		&nbsp;
		</td>
       
        <td class="<?php echo $class4;?>" align="left"><?php echo $rec_details['adTitle'];?></td>
      
		<td class="<?php echo $class4;?>" align="left">
		<?php 
		echo $rec_details['startDate']." to ".$rec_details['endDate'];
		?>
		</td>
		<td class="<?php echo $class4;?>" align="left">
			<?php
			echo $rec_details['adPrice'];
			?>
		</td>
		<td class="<?php echo $class4;?>" align="left">
<?php
if($rec_details['advertiseStatus']=='Y')
			{				
	 	?>
      			
				<a href="javascript:change_status('<?php echo $rec_details['id'];?>')" title="Activate Deactivate Status" class="register_link"> 
				<font color="#66CC00">Active</font></a>
      <? 	} 
			
	  		else
			{ ?>
      				<a href="javascript:change_status('<?php echo $rec_details['id'];?>')" title="Activate Deactivate Status" class="register_link"> <font color="#CC0000">Block</font></a>
      <? 
	  		} 
	  ?>
		</td>
		
        </tr>
	<?php
	}
	} // end if
	else
	{
	?>
	   <tr><TD colspan="10" align="center" class="font-12 black advertise_tableTxt">No records found</TD></tr>

	<?php
	}
	?>

       </table>

    </td>
  </tr>
</table>

   </td>
  </tr>
</table>

<!-- e table  -->

</td>
</tr>
</table></td>
                      </tr>
                      <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                    </table></td>
                    <td>&nbsp;</td>
                    </tr>
                </table></td>
              </tr>
            </table>
</form>
            
<?php
        //include("footer.php");
}
		?> 